#ifndef __USART_H__
#define __USART_H__

#include "stm32l4xx_ll_usart.h"
#include "stm32l4xx_ll_gpio.h"
#include "stm32l4xx_ll_rcc.h"
#include "stm32l4xx_ll_bus.h"
#include "stm32l4xx_ll_lpuart.h"


#include "stdbool.h"
#include <stddef.h>
#include <string.h>
#include "stdio.h"
#include "stm32l4xx_ll_lpuart.h"


#define USART1_BUFF_SIZE 2048
#define USART2_BUFF_SIZE 1024
#define USART3_BUFF_SIZE 1024
#define LPUART_BUFF_SIZE 2048

//串口枚举
typedef enum PORT_COM {
    PORT1_COM = 0,
    PORT2_COM,
    PORT3_COM,
    LPUART_COM,
} Port_com;

#pragma pack(1) //按照一个字节对齐
typedef struct PIPE_TYPE {
    unsigned char* buf;          // 缓冲区
    unsigned short size;         // 缓冲区大小
    volatile unsigned short pin; // 当前接收字节数
    volatile unsigned short sum; // 缓冲区字节数
    bool flag;                   // 处理标志
} Pipe_t;

typedef struct USART_HANDLE_T {
    Pipe_t* pipe;
    void (*pipe_remove)(Pipe_t* pipe, uint16_t len); //移除pipe数据
    void (*pipe_reset)(Pipe_t* pipe);               //复位pipie
    void (*Send)(char* info, uint16_t len);      //发送数据
} USUART_Handler_t;
#pragma pack()

void Usart1_init(void); //串口初始化函数
void Usart2_init(void);
void Usart3_init(void);
void LPUART_init(void);

bool Pipe_block_input(Pipe_t* Pipe, const uint8_t* packet, uint16_t len); //把数据放入Pipe中
void Usart_Link_Config(Port_com port_com, USUART_Handler_t* Port);//链接串口pipe和具体串口的函数


#endif /* __USART_H__ */
